/*
 * Copyright 2013-2015 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.xdtech.hotel.util;

import org.apache.commons.lang.StringUtils;

import com.thoughtworks.xstream.XStream;
import com.xdtech.hotel.protocol.vo.Ac;
import com.xdtech.hotel.protocol.vo.Component;
import com.xdtech.hotel.protocol.vo.Dimmer;
import com.xdtech.hotel.protocol.vo.Music;
import com.xdtech.hotel.protocol.vo.Node;
import com.xdtech.hotel.protocol.vo.Tv;
import com.xdtech.hotel.vo.DeviceLinkItem;

/**
 * 
 * @author max.zheng
 * @create 2015-5-3上午12:46:08
 * @since 1.0
 * @see
 */
public class ComponentHandler {

	/**
	 * 
	 * @author max.zheng
	 * @create 2015-4-22下午9:52:00
	 * @modified by
	 * @param deviceLinkItem
	 * @return
	 */
	public static Component loadComponent(DeviceLinkItem deviceLinkItem) {
		Component component = null;
		if(StringUtils.isBlank(deviceLinkItem.getComponent())) return component;
		
		if (HotelConstants.COMPONENT_MUSIC.equals(deviceLinkItem.getLtype()))
		{
			//音乐
			component = (Music)new XStream().fromXML(deviceLinkItem.getComponent());
		} else if (HotelConstants.COMPONENT_TV.equals(deviceLinkItem.getLtype()))
		{
			//电视
			component = (Tv)new XStream().fromXML(deviceLinkItem.getComponent());			
		} else if (HotelConstants.COMPONENT_AC.equals(deviceLinkItem.getLtype()))
		{
			//空调
			component = (Ac)new XStream().fromXML(deviceLinkItem.getComponent());			
		} else if (HotelConstants.COMPONENT_DIMMER.equals(deviceLinkItem.getLtype()))
		{
			//调光
			component = (Dimmer)new XStream().fromXML(deviceLinkItem.getComponent());			
		}else if (HotelConstants.COMPONENT_NODE.equals(deviceLinkItem.getLtype()))
		{
			//节点
			component = (Node)new XStream().fromXML(deviceLinkItem.getComponent());			
		}
		deviceLinkItem.setComp(component);
		return component;
	}
}
